@if($code == 0)
<div class="panel panel-success">
      <div class="panel-heading">
        <h3 class="panel-title">服务返回 {{$code}}</h3>
      </div>
      <div class="panel-body"  id ="ty-alert-redirect" data-redirect="{{$redirect}}" data-auto="{{$auto}}">
            <div class="alert alert-info" role="alert">
                <div id='ty-alert-timeout'></div>
                <strong>Oh code! </strong> {{$msg}}.
            </div> 
        url：<a href="{{$redirect}}">{{$redirect}}</a>
      </div>
</div>
@else
<div class="panel panel-danger">
      <div class="panel-heading">
        <h3 class="panel-title">服务返回 {{$code}}</h3>
      </div>
      <div class="panel-body" id ="ty-alert-redirect" data-redirect="{{$redirect}}" data-auto="{{$auto}}">
            <div class="alert alert-danger" role="alert" style="text-align:center;">
                <div id='ty-alert-timeout'></div>
                <strong>Oh shit!</strong> {{$msg}}.
            </div> 

        url：<a href="{{$redirect}}">{{$redirect}}</a>
      </div>
</div>

@endif
<script>
$(function(){

    
    var myAlert = {
        auto:0,
        count:5,
        redirect:function(){
            var $e = $('#ty-alert-redirect');
            var redirect = $e.data('redirect');
            this.auto = $e.data('auto');
            if (redirect.indexOf('http:') == -1) {
                redirect = 'http://' + redirect;
            } 
            $(location).attr('href', redirect);
        },
        timer:function(){
            var t = this;
            var timerr = setInterval(function(){
            
                $('#ty-alert-timeout').html(t.count);
                if (!t.count) {
                    clearInterval(timerr);
                }
                t.count--;
            }, 1000);

        },
        run:function(){
            var t = this;
            this.auto = {{$auto}} || '';
            if (!this.auto) {
                return;
            }
            this.timer();
            setTimeout(t.redirect, 5000);
        }
    }

    myAlert.run();
});
</script>
